package com.cxy.datawarehouse.controller;


import com.cxy.datawarehouse.biz.ElementBiz;
import com.cxy.datawarehouse.entity.Element;
import com.cxy.datawarehouse.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags="元素管理")
@RestController
@Validated
@Slf4j
@RequestMapping("/element")
public class ElementController {
    @Resource
    ElementBiz elementBiz;

    @GetMapping(value = "/list")
    @ApiOperation("元素列表")
    public Result<List<Element>> list() {
        List<Element> list = elementBiz.list();
        return Result.ok(list);
    }

    @GetMapping(value = "/getByTypeId/{id}")
    @ApiOperation("通过元素类别获取元素列表")
    public Result<List<Element>> getByTypeId(@PathVariable Long id) {
        List<Element> list = elementBiz.getByTypeId(id);
        return Result.ok(list);
    }

    @PostMapping(value = "/create")
    @ApiOperation("创建元素")
    public Result<Long> create(@RequestBody Element element) {
        elementBiz.create(element);
        return Result.ok();
    }

    @PostMapping(value = "/update")
    @ApiOperation("修改元素")
    public Result<Long> update(@RequestBody Element element) {
        elementBiz.update(element);
        return Result.ok();
    }

    @PostMapping(value = "/deleteById/{id}")
    @ApiOperation("删除元素")
        public Result<Long> deleteById(@PathVariable Long id) {
        elementBiz.deleteById(id);
        return Result.ok();
    }
}
